class AccountCashController {
    constructor($state,$rootScope, $scope, UserService, AccountService) {
        Object.assign(this, {$state,$rootScope, $scope, UserService, AccountService});
        this.$rootScope.currentGroup= this.$state.params.cg;
        this.bindCash = {};
        //this.init();
    }
    init(){
        let self = this;
        this.AccountService.getAccountInfo().then(_success).catch(_error);
        function _success(data) {
            self.bindCash.cash_account = data.cash_account;
            self.bindCash.cash_type_name = data.cash_type;
            self.bindCash.bank_name = data.bank_name;
            self.bindCash.bank_branch = data.bank_branch;
            self.bindCash.cash_user_name = data.cash_user_name;
        };
        function _error(reason) {
            console.log("AccountCashController.init(): "+ JSON.stringify(reason));
        };
    }


    /**
     * 绑定提现账户
     */
    bindAccountCash() {
        let self = this;
        console.log(self.bindCash);
        self.bindCash.user_name = self.bindCash.cash_user_name;
        self.AccountService.bindCashAccount(self.bindCash).then(_success).catch(_error);

        function _success(data) {
            if(data.success==true){
                layer.open({
                   icon:0,
                   title:"信息！",
                   content:"账户绑定成功！",
                   btn:["确定"],
                   yes:function (index,layerno) {
                       layer.close(index);
                       self.$state.reload();
                   }
               });
            }
        }
        function _error(reason) {
            let type = typeof reason;
            layer.open({
               icon:2,
               title:"错误！",
               content:type=='object'?reason.text:reason,
               btn:["好的"],
               yes:function (index,layerno) {
                   layer.close(index);
               }
           });
        }
    }
}

AccountCashController.$inject = ["$state","$rootScope", "$scope", "UserService", "AccountService"];

export default AccountCashController;